﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;

namespace SXFramWork.Core
{
    /// <summary>
    /// 数据仓储接口
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface IRepository<TEntity> where TEntity :class,new()
    {
        #region 操作实体
        /// <summary>
        /// 插入【实体】
        /// </summary>
        /// <param name="entity">插入的实体</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns>主键</returns>
        Task<string> InsertAsync(TEntity entity, IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 批量插入【实体】
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns>成功的条数</returns>
        Task<int> InsertAsync(IEnumerable<TEntity> list, IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 查询【实体】
        /// </summary>
        /// <param name="id">主键</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<TEntity> GetAsync(string id, IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 查询全部【实体】
        /// </summary>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<IEnumerable<TEntity>> GetAllAsync(IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 删除【实体】
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="unitOfWork"></param>
        /// <returns></returns>
        Task<bool> DeleteAsync(TEntity entity, IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 批量删除【实体】
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <param name="unitOfWork"></param>
        /// <returns></returns>
        Task<bool> DeleteAsync(IEnumerable<TEntity> list, IUnitOfWork unitOfWork = null);
        /// <summary>
        /// 更新【实体】
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<bool> UpdateAsync(TEntity entity, IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 批量更新【实体】
        /// </summary>
        /// <param name="list">实体集合</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<bool> UpdateAsync(IEnumerable<TEntity> list, IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 删除单条数据【谨慎使用】
        /// </summary>
        /// <param name="id">值</param>
        /// <param name="tableName">表名</param>
        /// <param name="propertyName">依照的属性名 默认["Id"]</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<int> DeleteAsync(dynamic id, string tableName, string propertyName = "Id", IUnitOfWork unitOfWork = null);

        /// <summary>
        /// 删除多条数据【谨慎使用】
        /// </summary>
        /// <param name="ids">值</param>
        /// <param name="tableName">表名</param>
        /// <param name="propertyName">依照的属性名 默认["Id"]</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<int> DeleteManyAsync(List<string> ids, string tableName, string propertyName = "Id", IUnitOfWork unitOfWork = null);
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="id">值</param>
        /// <param name="tableName">表名</param>
        /// <param name="propertyName">依照的属性名 默认["Id"]</param>
        /// <param name="unitOfWork">工作单元</param>
        /// <returns></returns>
        Task<bool> ExistsAsync(dynamic id, string tableName, string propertyName = "Id", IUnitOfWork unitOfWork = null);
        #endregion


    }
}
